package cc.wanforme.fsync.entity.po;

import cc.wanforme.fsync.entity.SyncMetaDto;
import cc.wanforme.fsync.util.DateTimeTool;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.time.LocalDateTime;

public class SyncLog {
    @TableId(type = IdType.AUTO)
    private Long id;

    // 组名
    private String name;

    // 源client
    private Long sourceClient;
    // 源文件夹路径
    private String source;

    // 备份地址
    private Long targetClient;
    // 新文件夹路径
    private String target;

    private String sourceBase;

    // server 的文件根路径，可以为 null。
    private String targetBase;
    /*重写规则 */
    private String rewritePath;

    // client 存在文件时，覆盖文件
    private Integer cover;

    // 备注
    private String mark;

    // 状态
    private String status;
    // 结果
    private String result;

    // 错误信息
    private String errorMsg;

    private String createTime;
    private String updateTime;

    public static SyncLog from(SyncMetaDto meta) {
        SyncLog log = new SyncLog();
        log.setName(meta.getName());
        log.setSource(meta.getSource());
        log.setTargetClient(meta.getClientNode().getId());
        log.setTarget(meta.getTarget());
        log.setRewritePath(meta.getRewritePath());
        log.setTargetBase(meta.getTargetBase());
        log.setSourceBase(meta.getSourceBase());
        log.setCover(meta.isCover() ? 1 : 0);
        log.setCreateTime(DateTimeTool.format(LocalDateTime.now()));
        return log;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getSourceClient() {
        return sourceClient;
    }

    public void setSourceClient(Long sourceClient) {
        this.sourceClient = sourceClient;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public Long getTargetClient() {
        return targetClient;
    }

    public void setTargetClient(Long targetClient) {
        this.targetClient = targetClient;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public String getMark() {
        return mark;
    }

    public void setMark(String mark) {
        this.mark = mark;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getRewritePath() {
        return rewritePath;
    }

    public void setRewritePath(String rewritePath) {
        this.rewritePath = rewritePath;
    }

    public Integer getCover() {
        return cover;
    }

    public void setCover(Integer cover) {
        this.cover = cover;
    }

    public void setSourceBase(String sourceBase) {
        this.sourceBase = sourceBase;
    }

    public String getSourceBase() {
        return sourceBase;
    }

    public void setTargetBase(String targetBase) {
        this.targetBase = targetBase;
    }

    public String getTargetBase() {
        return targetBase;
    }
}
